<?php

namespace App\Console\Commands;

use App\Console\Commands\Common\CommonCommand;
use App\Models\Rbac\GuardUser;
use App\Models\Rbac\GuardUserPrice;
use App\Models\User\ChengBao;

class CountPrice extends CommonCommand
{

    protected $signature = 'count:price {date?}';

    public function handle() {


         $date = $this->argument('date')??date('Y-m-d');
         //$date = '2022-10-09';
         //$guardUsers = GuardUser::where('id','>=',4)->get();
         $guardUsers = GuardUser::get();

         foreach ($guardUsers as $guardUser) {
            $info = $guardUser->countPrice($date);

            //dd($info);
            GuardUserPrice::updateOrCreate(['account'=>$guardUser->id,'date'=>$date],$info);
         }

        return 0;
    }
}
